package com.lanou.musicproject.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.lanou.musicproject.R;
import com.lanou.musicproject.event.MyEvent;
import com.lanou.musicproject.manager.SkinSettingManager;

import de.greenrobot.event.EventBus;

/**
 * Created by 王世美 on 15/11/3.
 * 换皮肤
 */
public class SkinInnerActivity extends Activity{
    private ImageView backIV;
    private SkinSettingManager mSkinSettingManager;
    private CheckBox cb_skin1, cb_skin2, cb_skin3,cb_skin4,cb_skin5,
            cb_skin6,cb_skin7,cb_skin8,cb_skin9,cb_skin10;
//    private CheckBox[] boxs = {cb_skin1, cb_skin2, cb_skin3};
//    private int boxState;
    //private int[] boxs = {R.id.cb_skin1, R.id.cb_skin2, R.id.cb_skin3};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_skin_main);
        mSkinSettingManager = new SkinSettingManager(this);
        backIV = (ImageView) findViewById(R.id.backIV);
        backIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();

            }
        });
        initView();
        bindEvent();
    }
    private void initView() {

        cb_skin1 = (CheckBox) findViewById(R.id.cb_skin1);
        cb_skin2 = (CheckBox) findViewById(R.id.cb_skin2);
        cb_skin3 = (CheckBox) findViewById(R.id.cb_skin3);
        cb_skin4 = (CheckBox) findViewById(R.id.cb_skin4);
        cb_skin5 = (CheckBox) findViewById(R.id.cb_skin5);
        cb_skin6 = (CheckBox) findViewById(R.id.cb_skin6);
        cb_skin7 = (CheckBox) findViewById(R.id.cb_skin7);
        cb_skin8 = (CheckBox) findViewById(R.id.cb_skin8);
        cb_skin9 = (CheckBox) findViewById(R.id.cb_skin9);
        cb_skin10 = (CheckBox) findViewById(R.id.cb_skin10);

//        SharedPreferences sharedPreferences = getSharedPreferences("meimei", MODE_PRIVATE);
//        boxState = sharedPreferences.getInt("num", 0);
        // 初始化默认皮肤
        mSkinSettingManager.initSkins();
//        boxs[boxState].setChecked(true);
        cb_skin1.setChecked(true);
    }

    private void bindEvent() {
        SkinCheckedChangeListener skinCheckListener = new
                SkinCheckedChangeListener();
        cb_skin1.setOnCheckedChangeListener(skinCheckListener);
        cb_skin2.setOnCheckedChangeListener(skinCheckListener);
        cb_skin3.setOnCheckedChangeListener(skinCheckListener);
        cb_skin4.setOnCheckedChangeListener(skinCheckListener);
        cb_skin5.setOnCheckedChangeListener(skinCheckListener);
        cb_skin6.setOnCheckedChangeListener(skinCheckListener);
        cb_skin7.setOnCheckedChangeListener(skinCheckListener);
        cb_skin8.setOnCheckedChangeListener(skinCheckListener);
        cb_skin9.setOnCheckedChangeListener(skinCheckListener);
        cb_skin10.setOnCheckedChangeListener(skinCheckListener);
    }

    /*
    *CheckBox Check选中变化事件监听类
     */
    private class SkinCheckedChangeListener implements
            CompoundButton.OnCheckedChangeListener{

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            switch (buttonView.getId()) {
                case R.id.cb_skin1:
                    if (isChecked) {
                        // 选中状态
                        mSkinSettingManager.selectSkinType(0);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(0));
                        cb_skin2.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin2:
                    if (isChecked) {
                        // 选中状态
                        mSkinSettingManager.selectSkinType(1);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(1));
                        cb_skin1.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin3:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(2);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(2));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin4:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(3);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(3));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin5:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(4);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(4));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin6:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(5);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(5));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin7:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(6);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(6));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin8:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(7);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(7));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin9:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(8);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(8));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin3.setChecked(false);
                        cb_skin10.setChecked(false);
                    }
                    break;
                case R.id.cb_skin10:
                    if (isChecked) {
                        // 选择状态
                        mSkinSettingManager.selectSkinType(9);
                        EventBus.getDefault().post(new MyEvent.ChangeSkin(9));
                        cb_skin1.setChecked(false);
                        cb_skin2.setChecked(false);
                        cb_skin4.setChecked(false);
                        cb_skin5.setChecked(false);
                        cb_skin6.setChecked(false);
                        cb_skin7.setChecked(false);
                        cb_skin8.setChecked(false);
                        cb_skin9.setChecked(false);
                        cb_skin3.setChecked(false);
                    }
                    break;
            }

        }
    }

  /*  @Override
    protected void onDestroy() {
        super.onDestroy();
        SharedPreferences sharedPreferences = getSharedPreferences("miemie", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("num", boxState);
        editor.commit();
        editor.clear();
    }*/
}
